<template>
  <el-table :data="goodsList" stripe border style="width: 100%">
    <!-- 多选 -->
    <el-table-column type="index" />

    <el-table-column prop="id" label="ID" width="300px" align="center" />

    <el-table-column prop="productNum" label="编号" align="center" />

    <el-table-column prop="productName" label="产品名称" align="center" />

    <el-table-column prop="cityName" label="出发城市" align="center" />

    <el-table-column prop="departureTime" width="180px" label="出发时间" align="center">
      <template v-slot="data">
        {{ isActive(data.row.departureTime) }}
      </template>
    </el-table-column>

    <el-table-column prop="productPrice" label="商品价格" align="center" />

    <el-table-column prop="productDesc" label="商品简介" align="center" />

    <el-table-column prop="productStatus" label="状态" align="center">
      <template v-slot="data">
        <el-tag type="success" v-if="data.row.productStatus === 1">开启</el-tag>
        <el-tag type="danger" v-else>关闭</el-tag>
      </template>
    </el-table-column>

    <!-- 操作 -->
    <el-table-column label="操作" width="130px" align="center">
      <template v-slot="data">
        <el-button-com size="mini" icon="el-icon-edit" @click.native="openUpdDialog(data.row.id)" />
        <el-button-com size="mini" btnType="danger" icon="el-icon-delete" @click.native="delItemById(data.row)" />
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
// 组件
import ElButtonCom from '@/components/common/ElButtonCom'

// 网络
import { delGoodById } from '@/network/goodListRequest'

export default {
  props: {
    goodsList: Array,
  },
  methods: {
    async delItemById(row) {
      // 删除操作
      const resConfirm = await this.$confirm('此操作将永久删除该商品, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).catch((err) => err)

      // 判断用户执行的操作
      if (resConfirm !== 'confirm') {
        return this.$message('取消删除')
      }
      // 执行删除
      this.delGoodByIdRequest(row.id)
    },
    async delGoodByIdRequest(id) {
      // 删除接口函数
      const { meta } = await delGoodById(id)
      if (meta.status !== 200) {
        console.log(meta)
        return this.$message.error(meta.msg)
      }
      this.$bus.$emit('getOrderData') // 刷新数据
      return this.$message.success(meta.msg)
    },
    isActive(number) {
      // 订单状态
      if (number != 1 && number != 0) {
        return '联系管理员'
      }
      return number == 1 ? '开启' : '关闭'
    },
    /**
     * 开启dialog
     */
    openUpdDialog(pid) {
      this.$bus.$emit('openUpdProductDialog', pid)
    },
  },
  components: {
    ElButtonCom
  },
}
</script>

<style lang="scss" scoped>
</style>